<%@ page import="com.thumb.service.impl.ThumbServiceImpl" %>
<%@ page import="com.thumb.bean.Thumb" %>
<%@ page import="java.util.List" %><%--
  Created by IntelliJ IDEA.
  User: zzx
  Date: 2020/9/8
  Time: 11:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<html>
  <head>
    <title>点赞模拟</title>
  </head>

  <%
    ThumbServiceImpl thumbService = new ThumbServiceImpl();
    List<Thumb> number = thumbService.findNumber();
    request.setAttribute("numbers",number);
  %>

  <body>
  <span id="thumbClick">点赞</span>
  <span id="thumbNumber" name="nowTimeNumber">
    <c:forEach items="${numbers}" var="data">
      ${data.number}
    </c:forEach></span>
  </body>

  <script src="js/jquery-3.5.0.min.js"></script>
  <script>
    $("#thumbClick").click(function (){

      var text = $(this).html();
      var text2 = $("#thumbNumber").html();
      if (text === "点赞"){
        $(this).html("取消点赞");
        $.ajax({
          url:"/thumb",
          data:"nowTimeNumber=" + text2,
          type:"post",
          dataType:"text",
          success:function (result) {
            $("#thumbNumber").html(result);
            console.log(result);
          }
        })
      }else {
        $("#thumbClick").html("点赞");
        $.ajax({
          url:"/thumb2",
          data:"nowTimeNumber=" + text2,
          type:"post",
          dataType: "text",
          success:function (result) {
            $("#thumbNumber").html(result);
          }
        })
      }
    });
  </script>
</html>
